home *** CD-ROM | disk | FTP | other *** search
- Path: ornews.intel.com!news
- From: thurman_b_miller@ccm2.hf.intel.com (Thurman Miller)
- Newsgroups: comp.lang.c++
- Subject: Re: When to use "->" vs "." when calling Member functions
- Date: Wed, 17 Jan 1996 17:13:12 GMT
- Organization: Intel Corporation
- Message-ID: <4djapd$j1m@ornews.intel.com>
- References: <4dhea1$6v8@ornews.intel.com> <30FC698D.6D216C84@eiffel.com>
- NNTP-Posting-Host: thurman-pc.ssd.intel.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- "Guus Leeuw jr." <guusl@eiffel.com> wrote:
-
- >Thurman Miller wrote:
- >>
- >> I'm confused, so please no harsh remarks :)
- >>
- >> If I've got:
- >>
- >> class Cfoo
- >> {
- >> something * getptr();
- >> somethingelse* m_other;
- >> }
- >>
- >> something * foo::getptr()
- >> {
- >> return m_other;
- >> }
- >>
- >> Now...if I'm in another class....
- >>
- >> Cfoo foo;
- >> somethingelse* = foo.getptr();
- >>
- >> why doesn't the following work?
- >>
- >> somethingelse* = foo->getptr();
- >>
- >> I get compile error about no "->" overloaded operator....
- >>
- >> Can someone point out the obvious when I use one notation over
- >> another?
- >>
- >> TIA
- >>
- >> Thurman
-
- >Okay, here we go.
-
- >When you write "foo->getptr()", you're actually writing
- >"(*foo).getptr()". And that is where your problem is.
-
- >The selector (`xyz->abc') is used as a shorthand notation for
- >`(*xyz).abc', and therefor can only be aplied to pointers to objects. As
- >in:
- > Cfoo *foo;
- > somethingelse* = foo->getptr();
-
- >Hope this explains,
- > Guus Leeuw jr.
-
- I would like to thank each of you for responding. Not only did you
- clear this up
- but you were all so consistent it is almost baffling!
-
- My original problem stemmed from using the document/view architecture
- and
- statements like the following:
-
- CRfcXferDoc* pDoc = (CRfcXferDoc*)GetDocument();
- pDoc->SetPlant(plantname);
-
- After reading your responses, I saw where my mistake was at. My
- example (using
- Cfoo) clearly does not match the actual code above that I had been
- basing my
- experience on. Each of your responses was so clear that I immediately
- recognized
- my error. (not to mention getting the same exact answer three times -
- I'm sure
- that helped as well! :)
-
- I was concentrating so much on the document that I didn't see the
- pointer. Oh
- well...Chalk it up to being a newbie.
-
-
- Thanks again!
-
- Thurman Miller
-
-
-